/**
 * Created by lesonli on 2016/11/15.
 */
import 'babel-polyfill';
import Vue from 'vue';
import App from './App';

import {
  sync
} from 'vuex-router-sync'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import './assets/style.css'
import store from './store';
import router from './config/router';
//import {HttpConfig} from './config/http';
import {
  MyEditor
} from './config/editor';
import {
  LocalFilters
} from './config/filters';
import {
  logout
} from './api/modules/auth';

import {
  getMyRole
} from './api/modules/roles'

//本地存储
import VueLocalStorage from 'vue-localstorage'

import {
  MessageBox
} from 'element-ui';

var VueTouch = require('vue-touch')
Vue.use(VueTouch, {name: 'v-touch'})

Vue.use(ElementUI)
Vue.use(VueLocalStorage)

// sync the router with the vuex store.
// this registers `store.state.route`
sync(store, router)

router.beforeEach((to, from, next) => {
  function browserRedirect() {
            var sUserAgent = navigator.userAgent.toLowerCase();
            var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
            var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
            var bIsMidp = sUserAgent.match(/midp/i) == "midp";
            var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
            var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
            var bIsAndroid = sUserAgent.match(/android/i) == "android";
            var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
            var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
            if ((bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {
                store.dispatch('set_device_type','phone')
            }
        }
        browserRedirect();
        next();
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
});